<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="col-sm-12">
        <div class="ibox">
            <div class="ibox-body">
                <div class="fixed-table-toolbar">
                    <div class="columns pull-left">
                        <button shiro:hasPermission="market:productArticle:add" type="button" class="btn  btn-primary"
                                onclick="add()">
                            <i class="fa fa-plus" aria-hidden="true"></i>添加文章
                        </button>
                        <!--<button shiro:hasPermission="market:productArticle:batchredis" type="button"
                                class="btn  btn-info"
                                onclick="batchredis();">
                            <i class="fa fa-trash" aria-hidden="true"></i>更新redis
                        </button>-->
                    </div>
                    <div class="columns pull-right">
                        <button class="btn btn-success" onclick="reLoad()">查询</button>
                    </div>
                    <div class="columns pull-right col-md-2 nopadding">
                        <select id="publishstate" class="form-control">
                            <option value="">-- 请选择发布状态 --</option>
                            <option value="1">已发布</option>
                            <option value="0">草稿</option>
                        </select>
                    </div>
                    <div class="columns pull-right col-md-2 nopadding">
                        <input type="text" id="articlehistorydate" name="articlehistorydate" class="form-control"
                               placeholder="请选择日期" readonly="readonly"
                               required="required" aria-required="true"
                        />
                    </div>
                    <div class="columns pull-right col-md-2 nopadding">
                        <select id="tagid" name="tagid"
                                class="form-control" type="text">
                            <option value="">---请选择标签---</option>
                        </select>
                    </div>
                    <div class="columns pull-right col-md-2 nopadding">
                        <select id="productid" onchange="getDistrict()" name="productid"
                                class="form-control" type="text">
                            <option value="">---请选择产品---</option>
                        </select>
                    </div>

                    <div class="columns pull-right col-md-2 nopadding">
                        <input id="articletitle" type="text" class="form-control"
                               placeholder="文章标题">
                    </div>
                </div>
                <table id="exampleTable" data-mobile-responsive="true">
                </table>
            </div>
        </div>
    </div>
</div>
<!--shiro控制bootstraptable行内按钮看见性 来自bootdo的创新方案 -->
<div>
    <script type="text/javascript">
        var s_edit_h = 'hidden';
        var s_remove_h = 'hidden';
        var s_resetPwd_h = 'hidden';
    </script>
</div>
<div shiro:hasPermission="market:productArticle:edit">
    <script type="text/javascript">
        s_edit_h = '';
    </script>
</div>
<div shiro:hasPermission="market:productArticle:remove">
    <script type="text/javascript">
        var s_remove_h = '';
    </script>
</div>
<div shiro:hasPermission="market:productArticle:resetPwd">
    <script type="text/javascript">
        var s_resetPwd_h = '';
    </script>
</div>
</div>
<div th:include="include :: footer"></div>
<script type="text/javascript" src="/js/appjs/market/productArticle/productArticle.js"></script>
<link rel="stylesheet" href="@{/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css}"
      th:href="@{/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css}">
<script th:src="@{/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js}"></script>
<script th:src="@{/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js}"></script>
<script type="text/javascript" th:inline="javascript">
    function batchredis() {
        $.ajax({
            url: "/market/productArticle/batchredis",
            type: "post",
            data: $('#signupForm').serialize(),
            success: function (r) {
                if (r.code == 0) {
                    layer.msg("操作成功");
                } else {
                    layer.alert("服务器错误!");
                }
            }
        });
    }

    $(function () {
        $.ajax({
            type: 'get',
            url: '/market/productChannel/listAllProduct?channelid=' + $("#channelid").val(),
            dataType: 'json',
            success: function (datas) {
                //返回list数据并循环获取
                var select = $("#productid");
                for (var i = 0; i < datas.length; i++) {
                    select.append("<option value='" + datas[i].id + "'>"
                        + datas[i].productName + "</option>");
                }
            }
        });
    })

    function getDistrict() {
        $("#tagid").empty();    //清空二级下拉框，否则会叠加
        // $("#sdkid").append("<option value='' selected='selected'>" + "---请选择---" + "</option>");
        /* var id = obj.id;
         var options = $("#" + id + " option:selected"); //获取选中的项
         alert(options.text()); //拿到选中项的值
         var countrycode = options.val();*/
        var productid = $("#productid").val();
        $.ajax({
            type: "post",
            url: '/market/productArticle/tagListByProductid',
            dataType: 'json',
            data: {productid: productid},
            success: function (data) {
                var select = $("#tagid");
                select.append("<option value='" + "" + "'>"
                    + "---请选择标签---" + "</option>");
                for (var i = 0; i < data.length; i++) {
                    select.append("<option value='" + data[i].id + "'>"
                        + data[i].tagName + "</option>");
                }
            }
        });
    }

    /*<![CDATA[*/

    /*]]>*/
    /**
     * 日期选择器
     * @param
     */
    $("#articlehistorydate").datetimepicker({//选择年月日
        format: 'mmdd',
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: 1,//显示‘今日’按钮
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        minView: 2,  //Number, String. 默认值：0, 'hour'，日期时间选择器所能够提供的最精确的时间选择视图。
        clearBtn: true,//清除按钮
        forceParse: 0
    });
</script>
</body>
</html>